/*  This file is part of -_-.

    -_- is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    -_- is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with -_-.  If not, see <http://www.gnu.org/licenses/>.

    Copyright 2012-2013 Oliver Katz */

#ifndef __COMMON_LIST_H
#define __COMMON_LIST_H

#include <stdio.h>
#include "data.h"

#define Z_WARNING_LIST(l, r) Z_WARNING_NULL(l, r);if((l)->content==NULL||(l)->head==NULL||(l)->head<(l)->content||(l)->size==0){Z_WARNING("cannot operate on illegal list: %s", #l);return r;}

//struct z_list: a list of z_data (memory block references)
typedef struct
{
	z_data *content; //memberof z_list: the buffer of data references
	z_data *head; //memberof z_list: the head or front of the list
	z_size size; //memberof z_list: allocated size of the buffer (in z_data)
} z_list;

z_list z_list_init(z_size init); //methodof z_list: initializer
//argof z_list_init: z_size init: the initial size of the list
int z_list_release(z_list l); //methodof z_list: uninitializer
z_size z_list_append(z_list *l, z_data e, z_size inc); //methodof z_list: append an element
//argof z_list_append: z_size inc: the increment size of the list (when you add new members, more memory is allocated in amount 'inc')
z_data z_list_get(z_list *l, z_size idx); //methodof z_list: get an element
z_data z_list_set(z_list *l, z_size idx, z_data e); //methodof z_list: set an element
z_size z_list_size(z_list *l); //methodof z_list: get the length of the list
int z_list_remove(z_list *l, z_size idx); //methodof z_list: remove an element from the list (shifts elements afterwards back as well)

/// This is mostly used for internal stuff. If you want a list type, use common/types/vector.h.

#endif